package gaml.testing;

import gaml.core.GamlConfig;
import gaml.error.GamlException;
import gaml.text.TextNodeBridge;
import gaml.text.YamlNodePrinter;
import gaml.text.YamlPrinterStore;
import gaml.text.YamlText;
import gaml.text.printer.AliasNodePrinter;
import gaml.text.printer.MappingNodePrinter;
import gaml.text.printer.ScalarNodePrinter;
import gaml.yaml.AliasNode;
import gaml.yaml.MappingNode;
import gaml.yaml.ScalarNode;
import gaml.yaml.ahchor.YamlAnchorCodeStore;

import org.junit.Test;


public class AliasNodePrinterTest {

	@Test
	public void testPrint () throws GamlException {
		YamlAnchorCodeStore anchors = new YamlAnchorCodeStore ();
		
		MappingNode map = new MappingNode (null);
		AliasNode alias = new AliasNode (map, anchors.getAnchor ("mapanch", map));
		map.addChild (new ScalarNode (map).setValue ("key"), alias);
		
		YamlPrinterStore store = new YamlPrinterStore ((YamlNodePrinter) new ScalarNodePrinter (GamlConfig.getDefault ()));
		store.register (new MappingNodePrinter (store, GamlConfig.getDefault ()));
		store.register (new AliasNodePrinter (GamlConfig.getDefault ()));
		
		System.out.println (new TextNodeBridge (new YamlText (), map).parseNode (store).getText ().getText ());
	}
}